cmake_minimum_required(VERSION 2.8)
project(fibio)

option(WITH_REDIS "Build Redis library" ON)
option(WITH_HTTP "Build HTTP library" ON)
option(WITH_MYSQL "Build MySQL library" ON)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -ftemplate-depth=256")
if(APPLE)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations -Wno-deprecated-register -Wno-macro-redefined")
    set(CMAKE_LINK_FLAGS "${CMAKE_LINK_FLAGS} -stdlib=libc++")
endif(APPLE)

find_package(Threads REQUIRED)
find_package(Boost 1.56.0 COMPONENTS system coroutine context thread REQUIRED)
find_package(OpenSSL REQUIRED)

IF((CMAKE_BUILD_TYPE MATCHES Debug) OR (NOT CMAKE_BUILD_TYPE))
    add_definitions(-DHAVE_VALGRIND_H)
ENDIF((CMAKE_BUILD_TYPE MATCHES Debug) OR (NOT CMAKE_BUILD_TYPE))

INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR})

set(FIBIO_DEPS)
list(APPEND FIBIO_DEPS fibio ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})

set(FIBIO_DEPS_INCS)
list(APPEND FIBIO_DEPS_INCS ${Boost_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR})

find_package(ZLIB)
find_package(Boost 1.56.0 COMPONENTS iostreams)
IF(ZLIB_FOUND AND Boost_FOUND)
	add_definitions(-DHAVE_ZLIB)
	INCLUDE_DIRECTORIES(AFTER ${ZLIB_INCLUDE_DIR})
	list(APPEND FIBIO_DEPS ${ZLIB_LIBRARIES})
	list(APPEND FIBIO_DEPS ${Boost_LIBRARIES})
	list(APPEND FIBIO_DEPS_INCS ${ZLIB_INCLUDE_DIR})
ENDIF(ZLIB_FOUND AND Boost_FOUND)

INCLUDE_DIRECTORIES(AFTER ${CMAKE_SOURCE_DIR}/include)

IF(WIN32)
	list(APPEND FIBIO_DEPS wsock32 ws2_32)
ENDIF(WIN32)

IF(WITH_MYSQL)
	find_package(MySQLConnectorCPP)
	IF(MYSQLCONNECTORCPP_FOUND)
		INCLUDE_DIRECTORIES(AFTER ${MYSQLCONNECTORCPP_INCLUDE_DIRS})
		list(APPEND FIBIO_DEPS ${MYSQLCONNECTORCPP_LIBRARIES})
		list(APPEND FIBIO_DEPS_INCS ${MYSQLCONNECTORCPP_INCLUDE_DIRS})
	ELSE(MYSQLCONNECTORCPP_FOUND)
		message("MySQL Connector/C++ is not found, disable MySQL support")
	ENDIF(MYSQLCONNECTORCPP_FOUND)
ENDIF(WITH_MYSQL)

set(FIBIO_LIBS fibio ${FIBIO_DEPS})

ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(test)
ADD_SUBDIRECTORY(example)

INCLUDE("CPackLists.txt")

enable_testing()
